#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2019/12/9 09:44|09:44
# @Author  : yangdingyi
# @File    : 二叉树的最大深度
# @Software: PyCharm


# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:

    def maxDepth(self, root: TreeNode) -> int:

        def work(nd: TreeNode) -> int:
            if not nd:
                return 0
            ld = work(nd.left)
            rd = work(nd.right)
            return (ld if ld >= rd else rd ) + 1

        return work(root)



